<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Kuyuan\Phpwidget\Date;

class RedRecord extends Model
{
    use HasFactory;
    protected $fillable = [
        'member_id',
        'red_id',
        'money',
        'pid',
        'go_to'
    ];

    /**
     * 获取用户信息
     */
    public function getNicknameAttribute()
    {
        return Member::where("id",$this->member_id)
            ->value('nickname');
    }

    /**
     * 时间
     * @return string
     */
    public function getTimeAttribute()
    {
        return Date::shortFormat(strtotime($this->created_at));
    }

    public function member()
    {
        return $this->hasOne(Member::class,"id","member_id");
    }
}
